package com.xoa.controller.BBS;

import com.xoa.model.BBS.BbsBoard;
import com.xoa.model.BBS.BbsBoardWithBLOBs;
import com.xoa.service.BBS.BbsBoardService;
import com.xoa.util.ToJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

// 讨论区设置
@Controller
@RequestMapping("system/bbs")
public class BbsController {


    @Autowired
    BbsBoardService bbsBoardService;


    /**
     * 主页面
     */
    @RequestMapping("/index")
    public String homePage(){
        return "/app/bbs/bbsSet/discussIndex";
    }

    /**
     * 新建讨论区
     */
    @RequestMapping("/new")
    public String newBbs(){
        return "app/bbs/bbsSet/new";
    }

    /**
     * 添加讨论区
     * @param record
     * @return
     */
    @RequestMapping("/addBoard")
    @ResponseBody
    public ToJson<BbsBoard> insertSelective(BbsBoardWithBLOBs record,HttpServletRequest request,Integer ifAddAffairs,Integer ifSms2Priv) {

        return bbsBoardService.insertSelective(record,request,ifAddAffairs,ifSms2Priv);
    }

    /**
     * 查询所有讨论区
     * @return
     */
    @RequestMapping("/selAll")
    @ResponseBody
    public ToJson<BbsBoard> selectAll(HttpServletRequest request,boolean purview,Integer page,Integer limit) {
        return bbsBoardService.selectAll(request ,purview,page,limit);
    }

    /**
     * 修改
     * @param record
     * @return
     */
    @RequestMapping("/updateBoard")
    @ResponseBody
    public ToJson<BbsBoard> updateByPrimaryKeyWithBLOBs(BbsBoardWithBLOBs record) {
        return bbsBoardService.updateByPrimaryKeyWithBLOBs(record);
    }

    /**
     * 删除
     * @param boardId
     * @return
     */
    @RequestMapping("/delBoard")
    @ResponseBody
    public ToJson<BbsBoard> deleteByPrimaryKey(Integer boardId) {
        return bbsBoardService.deleteByPrimaryKey(boardId);
    }


    /**
     * 查询单个详情
     * @param boardId
     * @return
     */
    @RequestMapping("/getDetail")
    @ResponseBody
    ToJson<BbsBoard> selectByPrimaryKey(Integer boardId) {
        return bbsBoardService.selectByPrimaryKey(boardId);
    }


    /**
     * 讨论区列表查询
     * @param
     * @return
     */
    @RequestMapping("/getComBoard")
    @ResponseBody
    public ToJson<BbsBoard> selectCommentBoard(HttpServletRequest request,BbsBoardWithBLOBs record) {
        return bbsBoardService.selectCommentBoard(request,record);
    }





}
